﻿using Common;
using DAL.DBUtility;
using Model;
using Model.AntiFake;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using Model.Origins;
using Enums;
using Enums.Sys;
namespace DAL.Origins
{
   public class QueryLogDAL
    {
    
    
       /// <summary>
       /// 添加日志
       /// </summary>
       /// <param name="model"></param>
       /// <returns></returns>
       public ResultEntity AddQueryLog(  QueryLogModel model) {
           string sql = @"  insert into Origins_QueryLog(WlCode,QueryType,QueryValue,QueryTime,QueryMessage,EnterpriseId,QueryAddress)
   values(@WlCode,@QueryType,@QueryValue,@QueryTime,@QueryMessage,@EnterpriseId,@QueryAddress)";
           SqlParameter[] parameters = {
                                      new SqlParameter("@WlCode",model.WlCode),
                                        new SqlParameter("@QueryType",model.QueryType),
                                          new SqlParameter("@QueryValue",model.QueryValue),
                                            new SqlParameter("@QueryTime",model.QueryTime),
                                              new SqlParameter("@QueryMessage",model.QueryMessage),
                                                //new SqlParameter("@NickName",model.NickName),
                                                  //new SqlParameter("@Status",model.Status),
                                                  new SqlParameter("@QueryAddress",model.QueryAddress),
                                                  
                                                  new SqlParameter("@EnterpriseId",model.EnterpriseId),
                                      };
           return DbHelperSQL.CommonResult(DbHelperSQL.ExecuteSql(sql, parameters));

       }


       /// <summary>
       /// 查询分页列表
       /// </summary>
       /// <param name="strWhere"></param>
       /// <returns></returns>
       public List<QueryLogModel> GetList(string strWhere)
       {
           //  string sql = @"  select * from Sys_User where ViewDel=@ViewDel and EnterpriseId=@EnterpriseId";
           string sql = @"select aq.ID,aq.WlCode,case  aq.QueryType when 0 then '网站' when 4 then '微信' else '' end as QueryType,
                 aq.QueryValue,aq.QueryTime,aq.QueryAddress,oe.EnterpriseName
                 
                 from Origins_QueryLog aq left join Organization_Enterprise oe
                 on aq.EnterpriseId=oe.ID {0}";
           sql = string.Format(sql, strWhere);
           SqlParameter[] parameters = {
                                            new SqlParameter("@ViewDel", EnumManagement.GetEnumValue(SysEnum.NoDele))
			};
           return ListDataSet.DataSetToIList<QueryLogModel>(DbHelperSQL.Query(sql, parameters)).ToList();
       }
    }
}
